#pragma once

#include "vtk_include.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define SIZE 10

struct cell_t
{
	unsigned short age;
	bool alive;
};

struct cell_display
{
	vtkTransformFilter *Transform;
	vtkSphereSource *Sphere;
};

class testGameOfLifeTimer : public vtkCommand 
{
public:
	testGameOfLifeTimer(void);
	~testGameOfLifeTimer(void);

	static testGameOfLifeTimer* New();
	void initialize(vtkRenderer*,vtkRenderWindowInteractor*);
	void setTimerToWatch(int);
	int getTimerToWatch();
	void setRenderer(vtkRenderer*);
	vtkRenderer* getRenderer();
	void setRenderWindowInteractor(vtkRenderWindowInteractor*);
	vtkRenderWindowInteractor* getRenderWindowInteractor();
	virtual void Execute(vtkObject *caller, unsigned long eid, void *callData);

protected:
	vtkSphereSource *cellSourceTemplate;
	vtkPolyDataMapper *cellMapperTemplate;
	vtkActor *cellActorTemplate;
	int currentStep;
	int timerToWatch;
	
	vtkRenderer *renderer;
	vtkRenderWindowInteractor *rwInteractor;
	vtkActor* universeActors[SIZE][SIZE][SIZE];
	cell_t universe[2][SIZE+2][SIZE+2][SIZE+2];
	vtkPolyData* cellMap[SIZE][SIZE][SIZE];

	void randomize();
	void count(int);
	void step();

	void destroyCellActor(int, int, int);
	void createCellActor(int, int, int);
	void addCell(vtkAppendPolyData*,int,int,int);
};
